<template>
  <div>
    <router-link to="/menu/add">
      <el-button type="danger">添加</el-button>
    </router-link>
    <!-- 全部打开：default-expand-all -->
    <el-table
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="type" label="类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.type==1" type="success" size="medium">目录</el-tag>
          <el-tag v-else type="danger" size="medium">菜单</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="icon" label="图标">
        <template slot-scope="scope">
          <i :class="scope.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="地址"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status==1" type="success" size="medium">已启用</el-tag>
          <el-tag v-else type="danger" size="medium">已禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-edit"
            circle
            size="mini"
            @click="edit(scope.row.id)"
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            size="mini"
            @click="del(scope.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template><script>
export default {
  data() {
    return {
      tableData: []
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.$http.get("menulist?istree=1").then(res => {
        this.tableData = res.data.list;
      });
    },
    edit(id) {
      this.$router.push("/menu/" + id);
    },
    del(id) {
      this.$confirm("确认删除吗,是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type:"warning",
        confirmButtonClass:"el-button--danger"
      })
        .then(res => {
          this.doDel(id);
        })
        .catch(_ => {});
    },
    doDel(id) {
      this.$http.post('/menudelete', {id}).then(res => {
        this.tableData = res.data.list;
      });
    } 
  }
};
</script>
<style lang="" >
.el-button {
  margin-bottom: 10px;
}
</style>